/**
 * Team members:
 * HengXing Liu 2022229044
 * YiYang Zhang 2022229047
 * ZeJun Liu 2022229092
 */
package project;


/**
 * define operator
 */
public class FunOp {
    private String opr;
    private int  arity;
    private int  priority;   //The lower the value, the higher the priority

    private boolean free;
    /**
     * proirity list
     * -1 : (
     * 0: -(UNARYMINUS),sin,cos,tan,abs
     * 1: ^
     * 2: * /
     * 3: + -
     * 4: )
     */
    public FunOp (String opr) {
        this.opr = opr;
        free = false;
        switch (opr.charAt(0)){
            case '^': arity = 2; priority = 1; break;
            case '*':
            case '/': arity = 2; priority = 2; break;
            case '+': arity = 2; priority = 3; break;
            case '(': arity = 0; priority = 5; break;
            case ')': arity = 0; priority = -2; break;
            case '-':
                if(opr.length() == 1){
                    arity = 2; priority = 3;
                }else{
                    arity = 1; priority = 0;
//                    this.opr = "-";
                }
                break;
            case ',': arity = 0; priority = 4;break;
        }
        switch(opr){
            case "sin":
            case "cos":
            case "tan":
            case "abs": arity = 1; priority = 0;break;
        }
    }

    public FunOp(String functionName, int arity){
        this.free = true;
        this.arity = arity;
        this.opr = functionName;
        this.priority = -1;
    }

    public int getArity(){ return this.arity; };
    public int getPriority(){ return this.priority; }
    public String getOpr() { return this.opr; }
    public boolean isfree(){
        return free;
    }
}
